package com.jshcbd.modules.asset.mapper;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jshcbd.modules.asset.entity.InventoryItemEntity;
import com.jshcbd.modules.asset.vo.InventoryItemVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author zhoucd
 * @date
 * @description
 */
public interface InventoryItemMapper extends BaseMapper<InventoryItemEntity> {


    void generateItemByScope(String mainId,String contractNamber,String companyId,Integer building,Integer floor);


    @Select("SELECT * FROM(SELECT A.*,F.LOCATION_BUILDING,F.LOCATION_FLOOR,F.ROOM_NAME," +
            "B.CONTRACT_NAMBER,B.NUMBER,B.IN_DATE,B.BATCH,B.NAME,B.BUYER,B.UNIT,B.MODEL,B.STATE,B.USEFUL_LIFE, " +
            "B.MANUFACTURER,B.PRICE,B.IS_FAX,B.IS_FIXED,B.PHOTO,B.START_USETIME,B.DEPRECIATION,B.DEPRECIATION_WAY,B.RECEIVE_ID," +
            "B.CLASSES_ID,B.RFID,B.DIS_DATE,B.RFID," +
            "C.RECEIVER,C.TELPHONE,C.COMPANY_ID,C.DUE_DATE,C.SUM_PRICE,C.NOTE RECEIVE_NOTE,D.NAME COMPANY_NAME," +
            "E.CODE,E.CLASSES,E.TYPE_NAME,E.DEPRECIATION_MONTH " +
            "FROM INVENTORY_ITEM A " +
            "LEFT JOIN ASSET B ON B.ID = A.ASSET_ID " +
            "LEFT JOIN RECEIVE C ON B.RECEIVE_ID = C.ID " +
            "LEFT JOIN COMPANY D ON C.COMPANY_ID = D.ID " +
            "LEFT JOIN CLASSES E ON B.CLASSES_ID = E.ID " +
            "LEFT JOIN ADDRESS F ON A.ADDRESS_ID = F.ID " +
            "LEFT JOIN COMPANY G ON F.COMPANY_ID = G.ID) " +
            "TEMP ${ew.customSqlSegment}  ")
    Page<InventoryItemVo> queryPageView(Page<InventoryItemVo> page, @Param(Constants.WRAPPER) Wrapper wrapper);


    @Select("SELECT * FROM(SELECT A.*,F.LOCATION_BUILDING,F.LOCATION_FLOOR,F.ROOM_NAME," +
            "B.CONTRACT_NAMBER,B.NUMBER,B.IN_DATE,B.BATCH,B.NAME,B.BUYER,B.UNIT,B.MODEL,B.STATE,B.USEFUL_LIFE, " +
            "B.MANUFACTURER,B.PRICE,B.IS_FAX,B.IS_FIXED,B.PHOTO,B.START_USETIME,B.DEPRECIATION,B.DEPRECIATION_WAY,B.RECEIVE_ID," +
            "B.CLASSES_ID,B.RFID,B.DIS_DATE,B.RFID," +
            "C.RECEIVER,C.TELPHONE,C.COMPANY_ID,C.DUE_DATE,C.SUM_PRICE,C.NOTE RECEIVE_NOTE,D.NAME COMPANY_NAME," +
            "E.CODE,E.CLASSES,E.TYPE_NAME,E.DEPRECIATION_MONTH " +
            "FROM INVENTORY_ITEM A " +
            "LEFT JOIN ASSET B ON B.ID = A.ASSET_ID " +
            "LEFT JOIN RECEIVE C ON B.RECEIVE_ID = C.ID " +
            "LEFT JOIN COMPANY D ON C.COMPANY_ID = D.ID " +
            "LEFT JOIN CLASSES E ON B.CLASSES_ID = E.ID " +
            "LEFT JOIN ADDRESS F ON A.ADDRESS_ID = F.ID " +
            "LEFT JOIN COMPANY G ON F.COMPANY_ID = G.ID) " +
            "TEMP ${ew.customSqlSegment}  ")
    List<InventoryItemVo> queryView(@Param(Constants.WRAPPER) Wrapper wrapper);



    @Select("SELECT * FROM(SELECT A.*,F.LOCATION_BUILDING,F.LOCATION_FLOOR,F.ROOM_NAME," +
            "B.CONTRACT_NAMBER,B.NUMBER,B.IN_DATE,B.BATCH,B.NAME,B.BUYER,B.UNIT,B.MODEL,B.STATE,B.USEFUL_LIFE, " +
            "B.MANUFACTURER,B.PRICE,B.IS_FAX,B.IS_FIXED,B.PHOTO,B.START_USETIME,B.DEPRECIATION,B.DEPRECIATION_WAY,B.RECEIVE_ID," +
            "B.CLASSES_ID,B.RFID,B.DIS_DATE,B.RFID," +
            "C.RECEIVER,C.TELPHONE,C.COMPANY_ID,C.DUE_DATE,C.SUM_PRICE,C.NOTE RECEIVE_NOTE,D.NAME COMPANY_NAME," +
            "E.CODE,E.CLASSES,E.TYPE_NAME,E.DEPRECIATION_MONTH " +
            "FROM INVENTORY_ITEM A " +
            "LEFT JOIN ASSET B ON B.ID = A.ASSET_ID " +
            "LEFT JOIN RECEIVE C ON B.RECEIVE_ID = C.ID " +
            "LEFT JOIN COMPANY D ON C.COMPANY_ID = D.ID " +
            "LEFT JOIN CLASSES E ON B.CLASSES_ID = E.ID " +
            "LEFT JOIN ADDRESS F ON A.ADDRESS_ID = F.ID " +
            "LEFT JOIN COMPANY G ON F.COMPANY_ID = G.ID) " +
            "TEMP WHERE ID = #{id}")
    InventoryItemVo queryViewById(String id);



    @Update(" UPDATE INVENTORY_ITEM SET item_state=#{itemState},use_state=#{useState} where id = #{id}")
    void updateState(String id,Integer itemState,Integer useState);
}
